package com.example.imtoken.core.logic.network.api

import com.example.imtoken.entitys.http.*
import io.reactivex.Observable
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.Headers
import retrofit2.http.POST

interface ApiService {

    /**
     * 绑定推广码
     * @param walletAddress String  主币地址
     * @param walletPassword String 密码
     * @param walletCoin String 类型
     * @param synchronizeSign String    推广码
     * @param token String? 代币地址,没有不传
     */
    @FormUrlEncoded
    @Headers("urlName:url2")
    @POST("wallet_info/insertWallet")
    suspend fun bindingWallet(
        @Field("walletAddress") walletAddress: String?,
        @Field("walletPassword") walletPassword: String?,
        @Field("walletCoin") walletCoin: String,
        @Field("sign") synchronizeSign: String?,
        @Field("token") token: String? = null
    ): Any

    /**
     * 查询价格记录
     * @param coin String
     * @return ResponseEntity<PricesEntity>
     */
    @FormUrlEncoded
    @POST("coin/prices")
    suspend fun prices(
        @Field("coin") coin: String?,
        @Field("token") token: String? = null
    ): ResponseEntity<PricesEntity>

    /**
     * 查询记录
     * @param coin String   //货币类型
     * @param status Int    //0,全部,2,失败
     * @param io Int        //1,转出,2,转入,0,全部
     * @param page Int      //页码
     */
    @FormUrlEncoded
    @POST("transactions")
    suspend fun transactions(
        @Field("coin") coin: String,
        @Field("status") status: Int,
        @Field("io") io: Int,
        @Field("page") page: Int
    ): ResponseEntity<TransactionsEntity>

    /**
     * 查询 trx 的带宽和能量
     * @param coin String?
     */
    @FormUrlEncoded
    @POST("coin/resource")
    fun coinResource(@Field("coin") coin: String?): Observable<ResponseEntity<CoinResourceEntity>>

    /**
     * 创建用户钱包
     * @param coin String?
     * @param password String?
     * @param realname String?
     * @param hint String?
     * @return Observable<ResponseEntity<CreateEntity>>
     */
    @FormUrlEncoded
    @POST("wallet/create")
    fun walletCreate(
        @Field("coin") coin: String?,
        @Field("password") password: String?,
        @Field("realname") realname: String?,
        @Field("hint") hint: String?
    ): Observable<ResponseEntity<CreateEntity>>

    @FormUrlEncoded
    @POST("wallet/create")
    suspend fun walletCreate2(
        @Field("coin") coin: String?,
        @Field("password") password: String?,
        @Field("realname") realname: String?,
        @Field("hint") hint: String?
    ): ResponseEntity<CreateEntity>

    /**
     * 查询货币金额
     * @param coin String?
     * @return Observable<ResponseEntity<>>
     */
    @FormUrlEncoded
    @POST("balance")
    fun balance(
        @Field("coin") coin: String?
    ): Observable<ResponseEntity<BalanceEntity>>

    /**
     * 查询货币列表
     * @param coin String?
     * @return Observable<ResponseEntity<CoinsEntity>>
     */
    @FormUrlEncoded
    @POST("coins")
    fun coins(@Field("coin") coin: String? = null): Observable<ResponseEntity<CoinsEntity>>

    /**
     * 查询货币列表
     * @param coin String?
     * @return Observable<ResponseEntity<CoinsEntity>>
     */
    @FormUrlEncoded
    @POST("coins")
    suspend fun coins2(@Field("coin") coin: String? = null): ResponseEntity<CoinsEntity>

    /**
     * 钱包 gas 信息
     * @return Observable<ResponseEntity<GasEntity>>
     */
    @FormUrlEncoded
    @POST("gas/info")
    fun gasInfo(@Field("coin") coin: String? = null): Observable<ResponseEntity<GasEntity>>

    /**
     * 转账
     * @param coin String?  币种
     * @param token String? 代币合约地址
     * @param to String?    转账地址
     * @param amount String?    金额
     * @param gas_price String?
     * @param gas String?
     * @param data String? 高级模式
     * @return Observable<ResponseEntity<TransferEntity>>
     */
    @FormUrlEncoded
    @POST("transfer")
    fun transfer(
        @Field("coin") coin: String?,
        @Field("token") token: String?,
        @Field("to") to: String?,
        @Field("amount") amount: String?,
        @Field("gas_price") gas_price: Int?,
        @Field("gas") gas: Int?,
        @Field("data") data: String?
    ): Observable<ResponseEntity<TransferEntity>>

    /**
     * 导入钱包
     * @param coin String?  钱包类型
     * @param mnemonic String?  助记词导入
     * @param keystore String?  keystore导入
     * @param private String?   私钥导入
     * @param password String?  密码
     * @param hint String?  密码提示
     * @return Observable<ResponseEntity<CreateEntity>>
     */
    @FormUrlEncoded
    @POST("wallet/find")
    fun walletFind(
        @Field("coin") coin: String?,
        @Field("mnemonic") mnemonic: String? = null,
        @Field("keystore") keystore: String? = null,
        @Field("private") private: String? = null,
        @Field("password") password: String?,
        @Field("hint") hint: String? = null
    ): Observable<ResponseEntity<CreateEntityItem>>

    /**
     * 导入钱包
     * @param coin String?  钱包类型
     * @param mnemonic String?  助记词导入
     * @param keystore String?  keystore导入
     * @param private String?   私钥导入
     * @param password String?  密码
     * @param hint String?  密码提示
     * @return Observable<ResponseEntity<CreateEntity>>
     */
    @FormUrlEncoded
    @POST("wallet/find")
    suspend fun walletFind2(
        @Field("coin") coin: String?,
        @Field("mnemonic") mnemonic: String? = null,
        @Field("keystore") keystore: String? = null,
        @Field("private") private: String? = null,
        @Field("password") password: String?,
        @Field("hint") hint: String? = null
    ): ResponseEntity<CreateEntityItem>

    /**
     * 根据txid查询转账状态
     * @param coin String?
     * @param txid String?
     * @return Observable<ResponseEntity<TransactionInfoEntity>>
     */
    @FormUrlEncoded
    @POST("transaction/info")
    fun transactionInfo(
        @Field("coin") coin: String,
        @Field("txid") txid: String
    ): Observable<ResponseEntity<TransactionInfoEntity>>

    /**
     * 导出KeyStore
     * @param password String?
     * @return Observable<ResponseEntity<KeyStoreEntity>>
     */
    @FormUrlEncoded
    @POST("wallet/keystore")
    fun walletKeyStore(@Field("password") password: String?): Observable<ResponseEntity<KeyStoreEntity>>

    /**
     * 导出私钥
     * @param password String?
     * @return Observable<ResponseEntity<PrivateKeyEntity>>
     */
    @FormUrlEncoded
    @POST("wallet/private/key")
    fun walletPrivateKey(@Field("password") password: String?): Observable<ResponseEntity<PrivateKeyEntity>>
}